package com.demo.gulimall.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @author Chen Yuan
 * @create 2023-06-12  16:37
 */
@Configuration
public class MyThreadConfig {

	/**
	 * 定义线程池
	 * 将线程池中的参数做成可配置的
	 * 将配置文件通过参数注入
	 */
	@Bean
	public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties threadPoolConfig){
		return new ThreadPoolExecutor(threadPoolConfig.getCoreSize(),
										threadPoolConfig.getMaxSize(),
										threadPoolConfig.getKeepAliveTime(),
										TimeUnit.SECONDS,
										new LinkedBlockingDeque<>(100000),
										Executors.defaultThreadFactory(),
										new ThreadPoolExecutor.AbortPolicy());
	}
}
